package com.example.idea.mapper;

import com.example.idea.entity.News;
import com.example.idea.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NewsMapper {

    @Insert("insert into news(title,description,content,authorid,time) values(#{title},#{description},#{content},#{authorid},#{time})")
    void add(News news);

    @Update("update news set title=#{title},description=#{description},content=#{content},authorid=#{authorid},time=#{time} where id=#{id}")
    void update(News news);

    @Delete("delete from news where id=#{id}")
    void delete(Integer id);

    User query(Integer id);

    @Delete("delete from news where id in (${ids})")
    void deleteBatch(String ids);

    List<News> list();

    List<News> selectList(News news);

    @Select("select * from news where title like concat('%',#{title},'%') and description like concat('%',#{description},'%') ORDER BY id DESC limit #{skipNum}, #{pageSize}")
    List<News> selectByPage(@Param("skipNum") Integer skipNum,
                            @Param("pageSize") Integer pageSize,
                            @Param("title") String title,
                            @Param("description") String description);

    @Select("select count(*) from news where title like concat('%',#{title},'%') and description like concat('%',#{description},'%')")
    Integer selectCountByPage(@Param("title") String title,
                              @Param("description") String description);
}
